﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.BLL;
using LGCourt.Logic.Common;
using KMFrame.Core;
using lgweb.common;
using LGCourt.Logic.NBL.DBEntities;

namespace lgweb.inside.FocusNews
{
    public partial class imglist : NeedValidatePage
    {
        private int _pageIndex = 1;
        public string _cate = "1";
        private string _cateName = "图片新闻";
        private string _dept = string.Empty;
        private string _keyword = string.Empty;
        private string _start = string.Empty;
        private string _end = string.Empty;
        public int _ClassID = 0;
        public string _picUrl = string.Empty;
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                _picUrl = System.Configuration.ConfigurationManager.AppSettings["InfoManage"];
                _picUrl = string.IsNullOrEmpty(_picUrl) ? "http://www.lgfygp.gov.cn/lgmanage/Systems/upload/" : _picUrl;
                GetParam();
                GetDepartmentList();
                GetList();
            }
        }

        private void GetParam()
        {
            this._keyword = string.IsNullOrEmpty(Request.QueryString["keyword"]) ? "" : Request.QueryString["keyword"];
            this._start = string.IsNullOrEmpty(Request.QueryString["start"]) ? "" : Request.QueryString["start"];
            this._end = string.IsNullOrEmpty(Request.QueryString["end"]) ? "" : Request.QueryString["end"];         
            this._pageIndex = string.IsNullOrEmpty(Request.QueryString["PageIndex"]) ? 1 : Convert.ToInt32(Request.QueryString["PageIndex"]);
        }

        //绑定部门
        private void GetDepartmentList()
        {
            DepartmentHandler bll = new DepartmentHandler();
            List<Department> result = (List<Department>)bll.GetDepartmentList();
            if (result != null && result.Count > 0)
            {
                Department PleaseLocation = new Department();
                PleaseLocation.Code = "0";
                PleaseLocation.Name = "选择部门";
                result.Insert(0, PleaseLocation);
                this.sltDepartment.DataSource = result;
                this.sltDepartment.DataTextField = "Name";
                this.sltDepartment.DataValueField = "Name";
                this.sltDepartment.DataBind();
                this.sltDepartment.Value = this._dept;
            }
        }

        private void GetList()
        {
            ColInfo bll = new ColInfo();          
            this.spBaoCate.InnerHtml = "图片新闻";           
                   
            QueryCondition param = new QueryCondition();
            param.PageSize = 16;
            param.PageIndex = this._pageIndex;
            if (!string.IsNullOrEmpty(this._start))
            {
                param.BegingDate = Utils.ConvertUnixTimeStampToDateTime(this._start);
            }
            if (!string.IsNullOrEmpty(this._end))
            {
                param.EndDate = Utils.ConvertUnixTimeStampToDateTime(this._end);
            }
            param.ClassID = _ClassID;
            param.keyword = this._keyword;
            param.from = this._dept;

            PageResult result = null;           
            result = (PageResult)bll.GetPicInfoPage(param);
            if (result != null && result.ResultList != null)
            {               
                this.rptInfoList.DataSource = (List<LGFY_Platform_NewsOfPic>)result.ResultList;
                this.rptInfoList.DataBind();
                this.pager1.RecordCount = result.TotalCount;
                this.pager1.TotalPage = result.PageCount;
                this.pager1.PageIndex = this._pageIndex;
                this.pager1.PageSize = 16;
                this.pager1.LinkUrl = string.Format("/inside/FocusNews/imglist.aspx?PageIndex={0}&keyword={2}&dept={3}&start={4}&end={5}&cate=0", this._pageIndex, _cate, this._keyword, this._dept, this._start, this._end);
            }
        }
    }
}